#!/bin/sh
echo "====start cppcheck xlcomm===="

cppcheck --std=c++14 xlcomm

echo "====start build xlcomm===="

set -x

SOURCE_DIR=`pwd`
BUILD_DIR=${BUILD_DIR:-build}
BUILD_TYPE=${BUILD_TYPE:-release}
INSTALL_DIR=${INSTALL_DIR:-install/${BUILD_TYPE}}
CXX=${CXX:-g++}

cd $SOURCE_DIR/xlcomm/net/protorpc && ./protoc.sh 
cd $SOURCE_DIR/xlcomm/net/example/myprotorpc && ./protoc.sh 
cd $SOURCE_DIR

mkdir -p $BUILD_DIR/$BUILD_TYPE \
  && cd $BUILD_DIR/$BUILD_TYPE \
  && cmake \
           -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
           -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
           -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
           $SOURCE_DIR \
  && make $* -j2

cd ${SOURCE_DIR}
rm -rf bin
mkdir bin
cp $BUILD_DIR/$BUILD_TYPE/bin/* bin/
rm *.log